package com.commons;

/**
 * Created by Tonight on 2017/3/16.
 */
public class PageModel <E>{

    //结果集
    private E Data;

    //查询记录数
    private int totalRecords;

    //每页多少条数据
    private int pageSize;

    //第几页
    private int pageNo;

    //总页数
    private int totalPages;

    public void setTotalPages(int totalPages) {
        this.totalPages = totalPages;
    }

    public E getData() {
        return Data;
    }

    public void setData(E data) {
        Data = data;
    }

    private String sql;

    public String getSql() {
        return sql;
    }

    public void setSql(String sql) {
        this.sql = sql;
    }

    /**
     * 总页数
     * @return
     */
    public int getTotalPages() {
        totalPages = (totalRecords + pageSize - 1) / pageSize;
        return totalPages;
    }

    /**
     * 取得首页
     * @return
     */
    public int getTopPageNo() {
        return 1;
    }

    /**
     * 上一页
     * @return
     */
    public int getPreviousPageNo() {
        if (pageNo <= 1) {
            return 1;
        }
        return pageNo - 1;
    }

    /**
     * 下一页
     * @return
     */
    public int getNextPageNo() {
        if (pageNo >= getBottomPageNo()) {
            return getBottomPageNo();
        }
        return pageNo + 1;
    }

    /**
     * 取得尾页
     * @return
     */
    public int getBottomPageNo() {
        return getTotalPages();
    }

    public int getTotalRecords() {
        return totalRecords;
    }

    public void setTotalRecords(int totalRecords) {
        this.totalRecords = totalRecords;
        getTotalPages();
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public int getPageNo() {
        return pageNo;
    }

    public void setPageNo(int pageNo) {
        this.pageNo = pageNo;
    }
}
